﻿using System;
using System.Text;

namespace HardToolApp.Model
{
    internal class SPISlaveModel : Communicate
    {
        SPIDataSize _dataSize;
        public SPIDataSize dataSize { get { return _dataSize; } set { SetProperty(ref _dataSize, value); } }
        SPIFirstBit _firstBit;
        public SPIFirstBit firstBit { get { return _firstBit; } set { SetProperty(ref _firstBit, value); } }
        SPI_CPHA _CPHA;
        public SPI_CPHA CPHA { get { return _CPHA; } set { SetProperty(ref _CPHA, value); } }
        SPI_CPOL _CPOL;
        public SPI_CPOL CPOL { get { return _CPOL; } set { SetProperty(ref _CPOL, value); } }
        UInt32 _timeout = 1000;
        public UInt32 timeout { get { return _timeout; } set { SetProperty(ref _timeout, value); } }
        byte _readLen = 4;
        public byte readLen { get { return _readLen; } set { SetProperty(ref _readLen, value); } }

        public SPISlaveModel() : base(CommCmd.COMM_SPI_SLAVE) { }


        public override string ToString()
        {
            switch (subCmd)
            {
                case 1:
                    StringBuilder sb = new StringBuilder();
                    sb.Append("改变SPI从机参数->数据长度:");
                    sb.Append(dataSize.ToString());
                    sb.Append(",");
                    sb.Append(firstBit == SPIFirstBit.SPI_MSB ? "MSB,频率:" : "LSB,频率:");
                    sb.Append(CPOL == SPI_CPOL.SPI_CPOL_LOW ? ",总线空闲时SCK为低" : ",总线空闲时SCK为高");
                    sb.Append(CPHA == SPI_CPHA.SPI_CPHA_1EDGE ? ",第一个边沿采样" : ",第二个边沿采样");
                    sb.Append("\n");
                    return sb.ToString();
                case 2:
                    return "SPI从机写入数据->" + sendBytes + "\n";
                case 3:
                    return "SPI从机读取" + readLen.ToString() + "个数据" + "\n";
                default:
                    return "未知命令" + "\n";
            }
        }
    }
}
